package com.lzz.bottomencapsulation.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.lzz.bottomencapsulation.holder.MvpRVViewHolder;

import java.util.List;


/**
 * <p>RecyclerView  的父适配器</p>
 */

public abstract class MvpBaseRecyclerAdapter<V extends MvpRVViewHolder> extends RecyclerView
        .Adapter<V> {
    protected View.OnClickListener onItemViewClickListener;//item内控件点击事件
    protected OnItemClickListener onItemClickListener;//item点击事件
    protected Activity activity;//activity
    protected Context context;//context

    public MvpBaseRecyclerAdapter(Context context) {
        this.context = context;
    }


    public MvpBaseRecyclerAdapter(Context context, View.OnClickListener
            onItemViewClickListener, OnItemClickListener onItemClickListener) {
        this.context = context;
        this.onItemViewClickListener = onItemViewClickListener;
        this.onItemClickListener = onItemClickListener;
    }


    /**
     * item点击事件回调接口
     */
    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    /**
     * item内控件的点击事件
     *
     * @param onItemClickListener
     */
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setOnItemViewClickListener(View.OnClickListener onItemViewClickListener) {
        this.onItemViewClickListener = onItemViewClickListener;
    }

    @Override
    public void onBindViewHolder(V holder, int position) {
        if (onItemClickListener != null) holder.setOnItemClickListener(onItemClickListener);
    }

    @Override
    public void onBindViewHolder(V holder, int position, List<Object> payloads) {
        super.onBindViewHolder(holder, position, payloads);
        if (onItemClickListener != null) holder.setOnItemClickListener(onItemClickListener);
    }
}
